﻿//====================================================================================================================
//Copyright (c) 2011 IdeaBlade
//====================================================================================================================
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
//documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
//the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 
//and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//====================================================================================================================
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of 
//the Software.
//====================================================================================================================
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 
//WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS 
//OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
//OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
//====================================================================================================================

using System;
using System.Security.Principal;
using IdeaBlade.Application.Framework.Core.Authentication;
using IdeaBlade.EntityModel;

namespace HelloWorld
{
    public class DesignTimeAuthenticationService : IAuthenticationService
    {
        #region Implementation of IAuthenticationManager

        /// <summary>
        /// Called by an EntityManager to request authentication credentials.
        /// </summary>
        /// <param name="targetEM">The EntityManager requesting credentials</param>
        /// <returns>
        /// True if the link was made
        /// </returns>
        /// <remarks>
        /// When called, the <b>IAuthenticationManager</b> can link its credentials
        ///             to the target EntityManager.  If the IAuthenticationManager does
        ///             not have credentials, or authenticated credentials, it should
        ///             return false to indicate that the target EntityManager should
        ///             try the usual Login processing for an anonymous user.  If credentials are available,
        ///             the <see cref="M:IdeaBlade.EntityModel.EntityManager.LinkForAuthentication(IdeaBlade.EntityModel.EntityManager)"/> method can be used to 
        ///             link credentials.
        /// </remarks>
        public bool LinkAuthentication(EntityManager targetEM)
        {
            return false;
        }

        #endregion

        #region Implementation of IAuthenticationService

        /// <summary>Current logged in user.</summary>
        /// <value>Returns the current logged in user or null for an anonymous user.</value>
        public IPrincipal Principal
        {
            get { return new UserBase(new UserIdentity("Admin")); }
        }

        /// <summary>Returns whether the user is logged in.</summary>
        /// <value>Returns true if user is logged in.</value>
        public bool IsLoggedIn
        {
            get { return true; }
        }

        /// <summary>Login with the supplied credential.</summary>
        /// <param name="credential">
        /// 	<para>The supplied credential.</para>
        /// </param>
        /// <param name="onSuccess">Callback called when login was successful.</param>
        /// <param name="onFail">Callback called when an error occured during login.</param>
        public INotifyCompleted Login(ILoginCredential credential, Action onSuccess, Action<Exception> onFail)
        {
            throw new NotImplementedException();
        }

        /// <summary>Logs out the current user.</summary>
        /// <param name="onSuccess">Callback called when logout was successful.</param>
        /// <param name="onFail">Callback called when an error occured during logout.</param>
        public INotifyCompleted Logout(Action onSuccess, Action<Exception> onFail)
        {
            throw new NotImplementedException();
        }

        /// <summary>Login with the supplied credential.</summary>
        /// <param name="credential">
        /// 	<para>The supplied credential.</para>
        /// </param>
        /// <param name="onSuccess">Callback called when login was successful.</param>
        /// <param name="onFail">Callback called when an error occured during login.</param>
        public INotifyCompleted LoginAsync(ILoginCredential credential, Action onSuccess, Action<Exception> onFail)
        {
            throw new NotImplementedException();
        }

        /// <summary>Logs out the current user.</summary>
        /// <param name="onSuccess">Callback called when logout was successful.</param>
        /// <param name="onFail">Callback called when an error occured during logout.</param>
        public INotifyCompleted LogoutAsync(Action onSuccess, Action<Exception> onFail)
        {
            throw new NotImplementedException();
        }

        public event EventHandler<EventArgs> LoggedIn;
        public event EventHandler<EventArgs> LoggedOut;
        public event EventHandler<EventArgs> PrincipalChanged;

        #endregion
    }
}
